home *** CD-ROM | disk | FTP | other *** search
- //
- // zoomer.js
- // A Portable Canvas Mode Image Zoomer
- //
-
- // True if we're using Navigator 4.0
- Nav40 = (document.layers) ? 1 : 0;
-
- // True if a zoomed window is open
- cmWinOpen = false;
-
- // Capture Click events
- if (Nav40) {
- document.captureEvents(Event.MOUSEDOWN);
- document.onmousedown = clicker;
- }
-
- function clicker(e) {
- // If an image is already showing, close the window
- if (cmWinOpen) {
- cmClose();
- return false;
- }
-
- // If the user clicked on a hyperlink that was one of our images,
- // open the image
- imURL = e.target.toString();
- imExt = imURL.substring(imURL.lastIndexOf(".") + 1, imURL.length);
- isImage = ( imExt == "gif" || imExt == "jpg" );
- if (isImage) {
- cmOpen(e)
- return false;
- }
-
- return true;
- }
-
- // A function that opens the canvas mode window
- function cmOpen(e) {
- // Enable universal write target
- netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
-
- // Set window features for Canvas Mode
- cmWinProps="titlebar=no,alwaysRaised=yes,dependent=yes
- cmWinProps+=",hotkeys=no,resizable=yes";
-
- // Put the window off-screen until it's resized
- cmWinProps+=",screenX=" + screen.width + ",screenY=" + screen.height;
-
- // Open the window
- cmWindow=window.open("","",cmWinProps);
-
- // Write the document to the new window
- cmWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
- Transitional//EN"><HTML><HEAD><TITLE>Image</TITLE><STYLE TYPE="text/css">#divIm { position:
- absolute; top: 0; left: 0 }</STYLE><BODY><DIV ID="divIm"><IMG SRC="' + e.target + '"></DIV>');
- cmWindow.document.close;
-
- // Get the width and height of the image and resize the window
- imWidth=cmWindow.document.divIm.document.images[0].width;
- imHeight=cmWindow.document.divIm.document.images[0].height;
- cmWindow.innerWidth=imWidth-4;
- cmWindow.innerHeight=imHeight-4;
-
- // Now move it into view, centered on the mouse pointer
- cmWindow.moveTo(e.screenX - (imWidth / 2) , e.screenY - (imHeight / 2));
-
- // Capture all mousedown events in it, so that a click will close it.
- cmWindow.enableExternalCapture;
- cmWindow.captureEvents(Event.MOUSEDOWN);
- cmWindow.onmousedown=cmClose ;
-
- // Update cmWinOpen so that we know an image is being displayed
- cmWinOpen = true;
- }
- // A function that simply closes the canvas mode window
- function cmClose() {
- cmWindow.close();
- cmWinOpen = false;
- }
-